<template>
    <base-breadcrumb>
        <searchData :searchData="searchArr" @search="search"></searchData>
        <a-card>
<!--            <div class="table-operator">-->
<!--                <a-button icon="plus" type="primary" @click="handleAdd" v-btnPermission="'bm_013_add_01'"-->
<!--                    >新增</a-button-->
<!--                >-->
<!--            </div>-->

            <list-table
                ref="table"
                size="default"
                rowKey="id"
                :columns="columns"
                :request="loadData"
                :alert="true"
                show-size-changer
                show-quick-jumper
                showPagination="auto"
                :isShowCountBar="false"
                :exportConfig="{ use: true,select: '总包结算策划',all: '总包结算策划'}"
                :exportPermission="{ select: 'bm_013_exp_03', all: 'bm_013_exp_03' }"
            >
                         <span
                                 slot="serial"
                                 slot-scope="text, record, index"
                         >{{ index + 1 }}</span>
                <div class="table-operateors mb20" slot="bottom">
                    <div class="pub-table-select-count" style="margin: 0 0 10px">
                        <a-icon type="info-circle" theme="twoTone" />
                        <span>
                        预计利润率(基本值)(%)：
                        <a>{{ from.settleBaseAmountRate }}</a>
                    </span>
                        <a-divider type="vertical" />
                        <span>
                        预计利润率(保底值(%)：
                        <a>{{ from.settleMinAmountRate }}</a>
                    </span>
                        <a-divider type="vertical" />
                        <span>
                        预计利润率(报送值)(%)：
                        <a>{{ from.settleReportAmountRate }}</a>
                    </span>
                    </div>
                </div>
                <span slot="operation" slot-scope="text, record">
                    <MoreButton>
                    <a @click="detailed(record)" v-btnPermission="'bm_013_loo_02'">查看</a>
                    <!-- 编辑 -->
                    <span
                        v-if="
                            (record.auditStatus != 'SUBMITTED' &&
                            record.auditStatus != 'PAST' &&
                            record.auditStatus != 'ABOLISH')&&hideBuquBtn()
                        "
                        v-btnPermission="'bm_013_edi_01'"
                    >
                        <a @click="addEdit(record)">编辑</a>
                    </span>
<!--                    &lt;!&ndash; 撤销 &ndash;&gt;-->
<!--                    <span v-if="record.auditStatus == 'SUBMITTED' && userId === record.creatorId&&hideBuquBtn()">-->
<!--                        <a @click="handleUndo({ id: record.id, type: 3 })">撤销</a>-->
<!--                    </span>-->
<!--                    &lt;!&ndash; 作废 &ndash;&gt;-->
<!--                    <span v-if="record.auditStatus == 'PAST'" v-btnPermission="'bm_013_tov_05'">-->
<!--                        <a @click="handleInvalid({ id: record.id, type: 2 })">作废</a>-->
<!--                    </span>-->
<!--                    &lt;!&ndash; 删除 &ndash;&gt;-->
<!--                    <span v-if="record.auditStatus == 'DRAFT'" v-btnPermission="'bm_013_del_03'">-->
<!--                        <a @click="handleRemoveParams({ id: record.id, type: 1 })">删除</a>-->
<!--                    </span>-->
                    <span
                        v-if="
                            record.auditStatus === 'PAST' ||
                            record.auditStatus === 'SUBMITTED' ||
                            record.auditStatus === 'REJECTED' ||
                            record.auditStatus === 'ABOLISH'
                        "
                        v-btnPermission="'bm_013_loo_02'"
                    >
                        <approval-button :status="record.auditStatus" :id="record.id"></approval-button>
                    </span>
                        </MoreButton>
                </span>
                <span slot="auditStatus" slot-scope="text, record">
                    <list-status
                        :status="record.auditStatus"
                        :isApproval="true"
                        conversion="en"
                        :text="text"
                    ></list-status>
                </span>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
const columns = [
    {
        title: '序号',
        width: '65px',
        scopedSlots: { customRender: 'serial' },
    },
    {
        title: '名称',
        dataIndex: 'name'
    },
    {
        title: '所属分公司',
        dataIndex: 'branchComName'
    },
    {
        title: '所属项目',
        dataIndex: 'projectName'
    },
    {
        title: '预计利润率(基本值)(%)',
        dataIndex: 'settleBaseAmountRate'
    },
    {
        title: '预计利润率(保底值)(%)',
        dataIndex: 'settleMinAmountRate'
    },
    {
        title: '预计利润率(报送值)(%)',
        dataIndex: 'settleReportAmountRate'
    },
    {
        title: '策划完成时间',
        dataIndex: 'compleDate'
    },
    {
        title: '填报人',
        dataIndex: 'createName'
    },
    {
        title: '填报时间',
        dataIndex: 'reportingTime'
    },
    {
        title: '状态',
        dataIndex: 'auditStatusName'
    },
    {
        title: '操作',
        dataIndex: 'operation',
        width: '170px',
        scopedSlots: { customRender: 'operation' }
    }
]
const searchArr = [
{
    name: '所属单位',
    valueKey: 'searchQuery',
    type: OrgTreeSelect,
  },
    {
        name: '策划完成时间',
        value: 'compleDate',
        type: 'dateRange'
    },
    {
        name: '填报人',
        value: 'creatorName',
        type: 'input'
    },
    {
        name: '填报时间',
        value: 'startEndDate',
        type: 'dateRange'
    },

    {
        name: '状态',
        value: 'auditStatus',
        type: 'select',
        data: [
            {
                value: '0',
                label: '待提交审批'
            },
            {
                value: '1',
                label: '审批中'
            },
            {
                value: '2',
                label: '审批通过'
            },
            {
                value: '3',
                label: '审批不通过'
            }
        ]
    }
]
import {
    getSettlementPlanningList,
    deleteSettlementPlanning,
    getSettlementPlanningListCount
} from '@/api/businessAffairs/revenueAndCost'
import OrgTreeSelect from '@/components/OrgTreeSelect'
import { typeListApproval } from '@/utils/util'
import BasePage from '@/views/basePage' // 基础配置
export default {
    name: 'a' + Date.now(),
    extends: new BasePage(),
    data() {
        this.columns = columns
        this.searchArr = searchArr
        return {
            queryParam: {},
            from: {},
            userId: JSON.parse(sessionStorage.getItem('ycloud-user_info')).id,
            loadData: (parameter) => {
                const requestParameters = Object.assign({}, parameter, this.queryParam)

                if (this.queryParam.startEndDate) {
                    requestParameters.createTimeBegin =
                        this.queryParam.startEndDate[0].format('YYYY-MM-DD HH:mm:ss') || void 0
                    requestParameters.createTimeEnd =
                        this.queryParam.startEndDate[1].format('YYYY-MM-DD HH:mm:ss') || void 0
                }
                if(this.queryParam?.compleDate) {
                    requestParameters.compleDateBegin =
                            this.queryParam.compleDate[0].format('YYYY-MM-DD') || void 0
                    requestParameters.compleDateEnd =
                            this.queryParam.compleDate[1].format('YYYY-MM-DD') || void 0
                    delete requestParameters.compleDate
                }
                this.getSettlementPlanningListCount(requestParameters)
                return getSettlementPlanningList(requestParameters).then((res) => {
                    const statusMap = {
                        'DRAFT': '待提交审批',
                        'SUBMITTED': '审核中',
                        'PAST': '审核通过',
                        'REJECTED': '审核不通过',
                        'ABOLISH': '已发布'
                    }
                    res.data.forEach(item=>{
                        item.auditStatusName = statusMap[item.auditStatus]
                        if(!item.createName) {
                            item.reportingTime = ''
                        }
                    })
                    console.log('数据返回对象：', res)
                    return res
                })
            },
            removeApi: {
                remove: deleteSettlementPlanning,
                invalid: deleteSettlementPlanning,
                undo: deleteSettlementPlanning
            }
        }
    },

    methods: {
        getSettlementPlanningListCount(requestParameters) {
            return getSettlementPlanningListCount(requestParameters).then((res) => {
                this.from = res.data
            })
        },
        //搜索
        search(value) {
            console.log(value)
            this.queryParam = value
            this.$refs.table.refresh(true)
        },
        // 收起展开
        toggleAdvanced() {
            this.advanced = !this.advanced
        },
        //新增
        handleAdd() {
            this.$router.push({
                path: '/businessAffairs/projectTotal/projectTotalAdd',
                query: {
                    id: '',
                    type: 'add'
                }
            })
        },
        // 查看
        detailed(e) {
            this.$router.push({
                path: '/businessAffairs/projectTotal/projectTotalAdd',
                query: {
                    id: e.id,
                    type: 'look'
                }
            })
        },
        //编辑
        addEdit(e) {
            this.$router.push({
                path: '/businessAffairs/projectTotal/projectTotalAdd',
                query: {
                    id: e.id,
                    type: 'edit'
                }
            })
        },
        // 删除草稿
        deleteDraft(e) {
            let that = this
            that.$confirm({
                title: '温馨提示',
                content: '确定是否删除数据？',
                okText: '确认',
                okType: 'danger',
                cancelText: '取消',
                onOk() {
                    return deleteSettlementPlanning(e)
                        .then((res) => {
                            that.$message.success('删除成功！')
                            that.$refs.table.refresh(true)
                        })
                        .catch((res) => {
                            that.$message.warning('删除失败！')
                        })
                }
            })
        }
        // // 删除草稿
        // deleteDraft(e) {
        //     deleteSettlementPlanning(e).then((res) => {
        //         if (res.data.code == 200) {
        //             this.$message.success('删除成功')
        //             this.$refs.table.refresh(true)
        //         }
        //     })
        // },
    }
}
</script>

<style lang="less">
.not-submit {
    display: inline-block;
    padding: 0;
    li {
        list-style: disc;
        color: red;
    }
}

.submitted {
    display: inline-block;
    padding: 0;
    li {
        list-style: disc;
        color: green;
    }
}
.alert-info {
    width: 100%;
    background-color: #e6f7ff;
    padding: 16px 0;
    margin-top: 10px;
    border-radius: 10px;
    .info-icon {
        margin: 0 6px 0 12px;
    }
    span {
        margin-right: 5px;
        color: #1890ff;
    }
}
</style>
